//
//  AppDelegate.swift
//  Order
//
//  Created by Lazyloading on 2020/7/1.
//  Copyright © 2020 lazyloading. All rights reserved.
//

import UIKit
import FWSideMenu
import IQKeyboardManagerSwift


let kMenuWidth = UIScreen.main.bounds.width * 0.7

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
 
        let login = BaseNavigationController.init(rootViewController: LoginController());
        let user = UserinfoModel.getInfo();
        
        self.window = UIWindow.init(frame: UIScreen.main.bounds);
        self.window?.rootViewController = (user?.token != nil) ? AppDelegate.transformMain() : login;
        self.window?.makeKeyAndVisible();
        
        IQKeyboardManager.shared.enable = true;
        IQKeyboardManager.shared.shouldResignOnTouchOutside = true;
        
        return true
    }
    
    func applicationWillResignActive(_ application: UIApplication) {

    }
    
    func applicationDidEnterBackground(_ application: UIApplication) {

    }
    
    func applicationWillEnterForeground(_ application: UIApplication) {
 
    }
    
    func applicationDidBecomeActive(_ application: UIApplication) {
    }
    
    func applicationWillTerminate(_ application: UIApplication) {
    }

    //MARK: 🐷 Method 🐷
    static func transformMain() -> UIViewController{
        let center = BaseNavigationController.init(rootViewController: HomeController());
        let left = LeftMenuController();
        
        let main = FWSideMenuContainerViewController.container(centerViewController: center, centerLeftPanViewWidth: 20, centerRightPanViewWidth: 20, leftMenuViewController: left, rightMenuViewController: nil);
        main.leftMenuWidth = kMenuWidth;
        main.sideMenuPanMode = .sideMenu;
        main.leftMenuWillShowBlock = {  container in
            left.getUserinfo();
        }
        
        return main;
    }
    
}

